//收藏相关
package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AppFavorite;
import com.ruoyi.system.service.IAppFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Objects;

/**
 * 收藏Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/app/system/favorite")
public class AppApiFavoriteController extends BaseController
{
    @Autowired
    private IAppFavoriteService appFavoriteService;

    /**
     * 查询收藏列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppFavorite appFavorite)
    {
        startPage();
        if (Objects.nonNull(getLoginAppUser())) {
            appFavorite.setUserId(getLoginAppUser().getUserId());
        }

        List<AppFavorite> list = appFavoriteService.selectAppFavoriteList(appFavorite);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppFavorite appFavorite)
    {
        List<AppFavorite> list = appFavoriteService.selectAppFavoriteList(appFavorite);
        ExcelUtil<AppFavorite> util = new ExcelUtil<AppFavorite>(AppFavorite.class);
        util.exportExcel(response, list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return success(appFavoriteService.selectAppFavoriteByFavoriteId(favoriteId));
    }

    /**
     * 新增收藏
     */
    @PostMapping
    public AjaxResult add(@RequestBody AppFavorite appFavorite)
    {
        return toAjax(appFavoriteService.insertAppFavorite(appFavorite));
    }

    /**
     * 修改收藏
     */
    @PutMapping
    public AjaxResult edit(@RequestBody AppFavorite appFavorite)
    {
        return toAjax(appFavoriteService.updateAppFavorite(appFavorite));
    }

    /**
     * 删除收藏
     */
	@DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(appFavoriteService.deleteAppFavoriteByFavoriteIds(favoriteIds));
    }
}
